package database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import config.Config;

public class JdbcConnection {

//	private static Connection conn = null;

	public static Connection getConnection() {
		Connection conn = null;
		try {
			String connStr = Config.getProperty(Config.JDBC_URL);
			String user = Config.getProperty(Config.JDBC_USER);
			String pwd = Config.getProperty(Config.JDBC_PWD);
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = (Connection) DriverManager.getConnection(connStr, user, pwd);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println(e.getMessage());
			conn = null;
		}
		return conn;
	}

	public static void closeConnection(Connection conn) {
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				System.out.println(e.getMessage());
			}
		}
	}

	public static void main(String[] args) {
		Connection conn = JdbcConnection.getConnection();
		JdbcConnection.closeConnection(conn);
	}

}
